home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-03 | 2.9 KB | 83 lines | [TEXT/MPS ] |
- /*************************************************************************************
- *
- * Object Oriented Shell
- *
- * Traps.cp - C Source
- *
- * Copyright © Apple Computer, Inc. 1988 - 1993
- * All rights reserved.
- *
- * This file has a bunch of test code to see if particular traps actually exist.
- * This is left over from two things: System 6.x and the 68K mac.
- * It's totally unnecessary if either of the above are unsupported.
- *
- *************************************************************************************/
-
- #include "main.h"
- #include <Traps.h>
-
- /**************************************************************************************
-
- TrapExists
-
- Check to see if a given trap is implemented. The recommended approach to
- see if a trap is implemented is to see if the address of the trap routine
- is the same as the address of the unimplemented trap. However, we must
- also make sure that the trap is contained in the trap table on the machine
- we're running on. Not all Macintoshes have the same size trap tables. We
- call NumToolboxTraps to find out thje size of the table. if the trap we are
- examing falls off the end, then we treat it as automatically being
- unimplemented.
-
- ***************************************************************************************/
- Boolean TrapExists(short theTrap)
- {
- TrapType theTrapType;
-
- theTrapType = GetTrapType( theTrap);
- if(( theTrapType == ToolTrap) && ((theTrap &= 0x07FF) >= NumToolboxTraps()))
- return false;
- else
- return (NGetTrapAddress( _Unimplemented, ToolTrap) !=
- NGetTrapAddress( theTrap, theTrapType));
- }
-
- /**************************************************************************************
-
- GetTrapType
-
- Check the bits of a trap number to determine its type. If bit 11 is set,
- it's a Toolbox trap. Otherwise, it's an OS trap.
-
- ***************************************************************************************/
- TrapType GetTrapType(short theTrap)
- {
- if(( theTrap & 0x0800) == 0)
- return(OSTrap);
- else
- return(ToolTrap);
- }
-
- /**************************************************************************************
-
- NumToolboxTraps
-
- Find the size of the Toolbox trap table. This can be either 0x0200 or
- 0x0400 bytes, depending on which Macintosh we are running on. We determine
- the size by taking advantage of an anomaly of the smaller trap table: any
- entries that fall byond the end of the trap table are mirrored back down into
- the lower part. For example, on a large table, trap numbers A86E and AA6E
- correspond to different routines. However, on a small table, they
- correspond to the same routine address. By chidking the addresses of these
- routines, we can determine the size of the table.
-
- ***************************************************************************************/
- short NumToolboxTraps( void)
- {
- if( NGetTrapAddress( 0xA86E, ToolTrap) == NGetTrapAddress( 0xAA6E, ToolTrap))
- return( 0x0200);
- else
- return( 0x0400);
- }
-
-